if( typeof console != 'undefined' ){ console.debug('view.js'); }

GW.menu.tools = 
        { text: "View Tools",                                                   // GewWiki tools
            submenu: { id: 'idEditSubmenu',
                itemdata: [
                    { text: 'Show Properties', id: 'idPropertiesMI', disabled: false, onclick: { fn: function(){ GW.showPagePropertiesDialog();}, scope: GW }},
                    { text: 'Edit Page', id: 'idEditMI', disabled: true, onclick: { fn: function(){ GW.editPage(); }, scope: GW }},
                    { text: 'New page', id: 'idNewMI', disabled: true, onclick: { fn: function(){ GW.newPage.show();}, scope: GW }},
                    { text: 'Log', onclick: { fn: GW.log.showHide, scope: GW.log }}
                ]
            }
        };

GW.pageOnLoad = function(){                                                     // onLoad
    GW.log.log( 'GW.pageOnLoad' );
    GW.configPage();
    GW.initPagePropertiesDialog();
    GW.displayFeaturePage.init();                                               // init feature page display facility
    GW.mapDiv.init();
    GW.pages[ GW.page.wikiTitle ] = GW.page;                                    // preload this page 
    GW.wait.hide();
};
GW.pageOnUnload = function(){                                                   // onUnload
    GW.log.log( 'GW.pageOnUnload' );
    GUnload();
};
GW.configPage = function(){                                                     // configure the page
    GW.menu.disabled( 'idEditMI', !GW.login );
    GW.menu.disabled( 'idNewMI', !GW.login );
    document.getElementById( 'idContent' ).innerHTML = GW.page['content'];
    GW.div.leftright( 'idLeft', 'idMap' );
};
GW.editPage = function(){                                                       // edit this page
    window.location = "/gw/editpage/" + GW.page['wikiTitle'];
};
GW.mapDiv = {                                                                   // support idMap div
    date: new Date(),                                                           // date/time 
    timer: 0,                                                                   // movezoom timer
    query: '',                                                                  // our query object
    init: function(){
        GW.mapDiv.map = new GW.map( 'idMap', false );
        if( GW.hash.havehash() ){                                               // have some hash, so use it
            GW.hash.initLLZT( GW.lat, GW.lon, GW.zoom, GW.maptype);
            GW.mapDiv.map.setLLZT( GW.lat, GW.lon, GW.zoom, GW.maptype );
        } else if( GW.page['bboxNorth'] != null ){
            GW.mapDiv.map.setLLZTfromBB( GW.page['bboxNorth'],
                                GW.page['bboxSouth'],
                                GW.page['bboxEast'],
                                GW.page['bboxWest'],
                                GW.maptype );
        } else {
            GW.mapDiv.map.setLLZT( GW.lat, GW.lon, GW.zoom, GW.maptype );
        }
        GW.mapDiv.map.showFeatures( GW.page['features'], false );
    }
};
GW.initPagePropertiesDialog = function(){                                       // init dialogue panels
    GW.pagePropertiesDialog = new YAHOO.widget.Dialog("idPagePropertiesDialog", // init page properties dialog
        { 
            postmethod: "none",
            fixedcenter : true,
            constraintoviewport: true,
            modal: true,
            visible : false, 
            buttons : [ { text:"Exit", handler: function(){this.cancel();}, isDefault:true } ]
        });
    GW.pagePropertiesDialog.render(document.body);
};

GW.showPagePropertiesDialog = function(){                                       // show the properties of this page
    GW.log.log('showPagePropertiesDialog');
    // put the page data in the form
    document.ppForm.pageGWTitle.value = GW.page['wikiTitle'];
    document.ppForm.pageRevision.value = GW.page['revision'];
    document.ppForm.pageCurrent.value = GW.page['current']
    document.ppForm.pageLocked.value = GW.page['locked'];
    document.ppForm.pageTitle.value = GW.page['title'];
    document.ppForm.pageAuthor.value = GW.page['nickname'];
    document.ppForm.pageDate.value = GW.page['date'];
    document.ppForm.pageTags.value = GW.serializeStringList( GW.page['tags'], '\n' );
    document.ppForm.pageFeatures.value = GW.serializeFeatureList( GW.page['features'], '\n' );
    document.ppForm.pageBox.value = GW.page['bboxNorth'] + '\n' + 
        GW.page['bboxSouth'] + '\n' + GW.page['bboxEast'] + '\n' + GW.page['bboxWest'];
    GW.pagePropertiesDialog.bringToTop();
    GW.pagePropertiesDialog.show();
};

if( typeof console != 'undefined' ){ console.debug('view.js'); }
